<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>添加员工信息</title>
    <script type="text/javascript">
      Ext.onReady(function(){

        var teamDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/team/getAllTeams'}),
          autoLoad:true,
          reader:new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'team'
          }, [
            {name:'name'},                            //用作后面的displayField:
            {name:'id'}                                //用作后面的valueField:
          ])
        });
        var teamIdCombo = new Ext.form.ComboBox({  //配合上面的departmentDS，完成动态生成的下拉框
          store: teamDS,
          hiddenName:'team_id',                //显示时：这里写后台传送过来的字段，一旦和valueField相等，就进行显示。不相等为空。
          displayField:'name',              //store里面的值，用于显示在表面上的值
          valueField:'id',                  //store里面的值，和display联动
          typeAhead: true,
          allowBlank: true,
          disable:true,
          minChars:1,
          readOnly:false,
          anchor:'90%',
          mode: 'remote',
          fieldLabel:'组队选择',
          forceSelection: true,
          triggerAction: 'all',
          emptyText:'请选择组队.....',
          selectOnFocus:true
        });

        var newWorkerForm=new Ext.form.FormPanel({
          width:400,
          labelAlign: 'top',
          url:'/worker/create',
          buttonAlign:'center',
          autoHeight:true,
          bodyStyle: 'padding:5px',
          labelWidth:100,
          waitMsgTarget: true,
          frame: true,
          items:[{
              xtype:'hidden',
              name:'id',
              value:''
            },{
              layout:'column',
              items:[{
                  columnWidth:1,
                  layout:'form',
                  items:[{
                      xtype:'textfield',
                      fieldLabel: '员工名',
                      name: 'name',
                      allowBlank:false,
                      anchor:'90%'
                    },{
                      xtype:'numberfield',
                      fieldLabel: '编号',
                      name:'number',
                      allowBlank:false,
                      anchor:'90%'
                    },teamIdCombo]
                }]
            }],
          buttons:[{
              text:'确定',
              handler: function(){
                // check form value
                if (newWorkerForm.form.isValid()) {
                  newWorkerForm.form.submit({
                    method: 'post',
                    waitMsg: '正在创建账号...',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        newWorkerWin.destroy();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                newWorkerWin.destroy();
              }
            }]
        });
        newWorkerForm.render('newWorkerForm');
      })
    </script>
  </head>
  <body>
    <div id="newWorkerForm"></div>
  </body>
</html>
